import java.util.ArrayList;
import java.util.List;

public class Solution658 {
    public List<Integer> findClosestElements(int[] arr, int k, int x) {
        int ans=0;
        for (int i=k;i<arr.length;i++){
            if (Math.abs(arr[i]-x)<Math.abs(arr[i-k]-x)){
                ans=i-k+1;
            }else if (Math.abs(arr[i]-x)>Math.abs(arr[i-k]-x)){
                break;
            }
        }
        List<Integer> list=new ArrayList<>();
        for (int i=ans;i<ans+k;i++){
            list.add(arr[i]);
        }
        return list;
    }

    public static void main(String[] args) {
        System.out.println(new Solution658().findClosestElements(new int[]{0,0,0,1,3,5,6,7,8,8},2,2));
    }
}
